//
//  HWMyDetailViewController.m
//  HWanGame
//
//  Created by 陈道斌 on 2019/10/24.
//  Copyright © 2019 Chendaobin. All rights reserved.
//

#import "HWMyDetailViewController.h"
#import "HWBalanceMingxiViewController.h" // 收支明细
#import "HWintegralDetailViewController.h"
#import "HWYuEMingXiViewController.h"

@interface HWMyDetailViewController ()<UIScrollViewDelegate>

@property (strong,nonatomic) UIView *whiteView;
@property (strong,nonatomic) NSArray *dataArr;
@property (strong,nonatomic) NSArray *icoImageArr;
@property (nonatomic, weak) UIScrollView *contentScrollView;
@property (nonatomic,strong) NSMutableArray *labelMuArr;
@property (nonatomic, weak) UILabel *selectLabel;

@end

@implementation HWMyDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
     [self addControlsView];
       
         //添加控制器
    [self addcontroller];
        // 设置滑动控制器
    [self setupContentScrollView];
         //
    [self setupOneViewController:0];
   
}



// 添加控件
-(void)addControlsView {
    
    
    
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"我的账单";
    
    
     self.whiteView = [[UIView alloc]initWithFrame:CGRectMake(0, NavBarHeight, SCREEN_WIDTH, 127)];
      self.whiteView.backgroundColor = [UIColor  whiteColor ];
      
      
      [self.view addSubview:self.whiteView];
      
      
      UIView *baseview = [[UIView alloc]initWithFrame:CGRectMake(23, 12, SCREEN_WIDTH-23*2, 100)];
      baseview.backgroundColor = RGB(255, 255, 255);
      baseview.layer.cornerRadius = 12;
      baseview.layer.masksToBounds = YES;
      
      baseview.layer.shadowColor = [UIColor colorWithRed:26/255.0 green:113/255.0 blue:255/255.0 alpha:0.2].CGColor;
      baseview.layer.shadowOffset = CGSizeMake(6,6);
      baseview.layer.shadowOpacity = 1;
      baseview.layer.shadowRadius = 5;
      baseview.layer.cornerRadius = 12;
      baseview.layer.masksToBounds = YES;
      baseview.clipsToBounds = NO;

      [self.whiteView addSubview:baseview];
      
      self.dataArr = @[@"收支明细",@"积分明细",@"余额明细"];
      self.icoImageArr = @[@"youxi_Ico",@"goodsshangping",@"shangpingbudai"];
      CGFloat w =  (SCREEN_WIDTH- 60*3-23*2)/6;
      
      self.labelMuArr = [[NSMutableArray alloc]init];
      for (int i = 0; i < self.dataArr.count; i++) {
          int numshu = (i+1)*2-1;
          UIView *redview =  [[UIView alloc]initWithFrame:CGRectMake(w*numshu+i*60, 19, 60, 52)];
          [baseview addSubview:redview];
          
          UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(15, 5, 30, 30)];
          imageView.image  = [UIImage imageNamed:self.icoImageArr[i]];
          imageView.tag = i;
          UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapView:)];
          imageView.userInteractionEnabled = YES;
          [imageView addGestureRecognizer:tap];
          [redview addSubview:imageView];
      
          UILabel *texelabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 40, 60, 12)];
          texelabel.textAlignment = NSTextAlignmentCenter;
          texelabel.textColor = RGB(51, 51, 51);
          texelabel.text = self.dataArr[i];
          texelabel.font = [UIFont systemFontOfSize:12];
          [redview addSubview:texelabel];
          if (i == 0 ) {
              texelabel.textColor = RGB(26, 133, 255);
              self.selectLabel = texelabel;
              
          }
          [self.labelMuArr addObject:texelabel];
         
          
      }
    
}


#pragma mark ------    添加控制器
- (void)addcontroller {
    HWBalanceMingxiViewController *interative =  [[HWBalanceMingxiViewController alloc]init];
    [self addChildViewController:interative];

    HWintegralDetailViewController *notive = [[HWintegralDetailViewController alloc]init];
    [self addChildViewController:notive];

    HWYuEMingXiViewController *xiaoxi = [[HWYuEMingXiViewController alloc]init];
    [self addChildViewController:xiaoxi];
    
    
    
    
    
    
    
    
    
}


#pragma mark ------        点击图片跳转
- (void)tapView:(UITapGestureRecognizer *)sender {
    UILabel *view = (UILabel *)sender.view;
    UILabel *label =  self.labelMuArr[view.tag];
    [self selLabel:label];
    NSInteger i = view.tag;
    // 2.把对应子控制器的view添加上去
    [self setupOneViewController:i];
    
    // 3.内容滚动视图滚动到对应的位置
    CGFloat x = i * [UIScreen mainScreen].bounds.size.width;
    self.contentScrollView.contentOffset = CGPointMake(x, 0);
    
    
    
}

- (void)selLabel:(UILabel  *)label
{
   // [_selectButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    self.selectLabel.textColor = RGB(51, 51, 51);
    label.textColor = RGB(26, 133, 255);
     self.selectLabel= label;
    

    
    
}



//  设置导航栏属性
- (void)navigationAttribute {
    self.navigationItem.title = @"消息中心";
    self.navigationItem.title = [HWjianzhiduiObject keylocalization:@"消息中心"];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    UIImage *image = [UIImage imageOriginalWithName:@"messagr_clear"];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithImage:image style:UIBarButtonItemStylePlain target:self action:@selector(buttonItemTap)];

    
    
}

#pragma  mark  --------  删除按钮
- (void)buttonItemTap {
    
    DLog(@"删除按钮");
    
}




#pragma mark - 添加内容滚动视图
- (void)setupContentScrollView
{
    // 创建contentScrollView
    UIScrollView *contentScrollView = [[UIScrollView alloc] init];
    CGFloat y = NavBarHeight + 127;
    contentScrollView.frame = CGRectMake(0, y, self.view.bounds.size.width, self.view.bounds.size.height - y);
    [self.view addSubview:contentScrollView];
    _contentScrollView = contentScrollView;
    
    // 设置contentScrollView的属性
    // 分页
    self.contentScrollView.pagingEnabled = YES;
    // 弹簧
    self.contentScrollView.bounces = NO;
    // 指示器
    self.contentScrollView.showsHorizontalScrollIndicator = NO;
    
    contentScrollView.backgroundColor = [UIColor whiteColor];
    
    // 设置代理.目的:监听内容滚动视图 什么时候滚动完成
    self.contentScrollView.delegate = self;
    self.contentScrollView.contentSize = CGSizeMake(3 * kScreenW, 0);
    
    
}


// 只要一滚动就需要字体渐变
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    // 字体缩放 1.缩放比例 2.缩放哪两个按钮
    NSInteger leftI = scrollView.contentOffset.x / kScreenW;
    
//    UIButton *leftBtn = self.titleButtons[leftI];
//
//    // 1.标题颜色 变成 红色
    UILabel *label = self.labelMuArr[leftI];
    [self selLabel:label];
//
    // 添加控制器
    [self setupOneViewController:leftI];
    
    
    
}





#pragma mark - 添加一个子控制器的View
- (void)setupOneViewController:(NSInteger)i
{
    
    UIViewController *vc = self.childViewControllers[i];
    if (vc.view.superview) {
        return;
    }
    CGFloat x = i * [UIScreen mainScreen].bounds.size.width;
    vc.view.frame = CGRectMake(x, 0,   kScreenW, self.contentScrollView.bounds.size.height);
    [self.contentScrollView addSubview:vc.view];
}










@end
